package com.example.demo.controller;


import com.example.demo.po.Response;
import com.example.demo.po.User;
import com.example.demo.service.MyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
@RequestMapping("/api")
public class MyController {

    @Autowired
    MyService service;

    @Autowired
    Response response;

    @RequestMapping("/login")
    public Response Login(User user){
        String password = service.getPassword(user);
        if (password.equals(user.getPassword())){
            response.success();
            Map<String,String> data = new HashMap<>();
            data.put("user",user.getUsername());
            response.setData(data);
            return response;
        }else {
            response.fail();
            return response;
        }

    }

    @RequestMapping("/register")
    public Response Register(User user){
        int rows = service.Register(user);
        if (rows>0){
            response.success();
        }else {
            response.fail();
        }
        return response;
    }

    @RequestMapping("/getInfo")
    public User getInfo(String username){
        return service.getInfo(username);
    }


}
